﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using NewComer06.MVP;

namespace NewComer06.VisualWebPartNewComer
{
    public partial class VisualWebPartNewComerUserControl : UserControl, IComerView
    {
        ComerPresenter _present;

        protected void Page_Load(object sender, EventArgs e)
        {
            _present = new ComerPresenter(this);
            _present.DataBind();

        }

        public System.Collections.Generic.List<Comer> listComers
        {
            get;
            set;
        }

        protected void RenderByCtrl(string htmlStr)
        {
            Controls.Add(new LiteralControl(htmlStr));
        }

        protected void DocumentsRenderTableHeader()
        {
            Controls.Add(new LiteralControl("<table >"));
            Controls.Add(new LiteralControl("<tr>"));
            Controls.Add(new LiteralControl("<td class=borderTable>"));
            Controls.Add(new LiteralControl("<table class=\"tableBorder\">"));
            Controls.Add(new LiteralControl("<tr>"));
            Controls.Add(new LiteralControl("<td class=title>New Comers"));
            Controls.Add(new LiteralControl("</td>"));
            Controls.Add(new LiteralControl("</tr>"));
            Controls.Add(new LiteralControl("</table>"));
            Controls.Add(new LiteralControl("</td>"));
            Controls.Add(new LiteralControl("</tr>"));
            Controls.Add(new LiteralControl("<tr>"));
            Controls.Add(new LiteralControl("<td>"));
            Controls.Add(new LiteralControl("<table class=\"tableBorder\">"));

            foreach (Comer th in listComers)
            {

                Controls.Add(new LiteralControl("<tr>"));
                Controls.Add(new LiteralControl("<td class=\"name\">"+th.FirstName+" "+th.LastName));
                Controls.Add(new LiteralControl("</td>"));
                Controls.Add(new LiteralControl("<td>"));
                Controls.Add(new LiteralControl("</td>"));
                Controls.Add(new LiteralControl("<td rowspan=\"2\" class=\"imageBorder\">"));
                Controls.Add(new LiteralControl("<img alt=\"\" src=" + th.Picture.Substring(0, th.Picture.Length - 2) + " />"));
                Controls.Add(new LiteralControl("</td>"));
                Controls.Add(new LiteralControl("</tr>"));
                Controls.Add(new LiteralControl("<tr>"));
                Controls.Add(new LiteralControl("<td>"+th.Jobtitle));
                Controls.Add(new LiteralControl("</td>"));
                Controls.Add(new LiteralControl("<td>"));
                Controls.Add(new LiteralControl("<a href=\"http://w3schools.com/html/tryit.asp?filename=tryhtml_pulpitimage\">Read More"));
                Controls.Add(new LiteralControl("</a>"));
                Controls.Add(new LiteralControl("</td>"));
                Controls.Add(new LiteralControl("</tr>"));
                Controls.Add(new LiteralControl("<tr>"));
                Controls.Add(new LiteralControl("<td colspan=3>"));
                Controls.Add(new LiteralControl("<hr size=\"1\" align=\"center\" class=\"styleHr\"/>"));
                Controls.Add(new LiteralControl("</td>"));
                Controls.Add(new LiteralControl("</tr>"));

            }
            Controls.Add(new LiteralControl("<tr>"));
            Controls.Add(new LiteralControl("<td colspan=\"3\" style=\"padding-bottom:20px\">"));
            Controls.Add(new LiteralControl("<a href=\"http://training-sp06:8081/Shared%20Documents/ShowAll.aspx\">All new comers"));
            Controls.Add(new LiteralControl("</a>"));
            Controls.Add(new LiteralControl("</td>"));
            Controls.Add(new LiteralControl("</tr>"));
            Controls.Add(new LiteralControl("</table>"));
            Controls.Add(new LiteralControl("</td>"));
            Controls.Add(new LiteralControl("</tr>"));
            Controls.Add(new LiteralControl("</table>"));

        }




        public void TableBinding()
        {
            DocumentsRenderTableHeader();
        }
    }
}
